<template>
	<view class="main-view">
		<swiper class="content-swiper" :indicator-dots="indicatorDots" :autoplay="autoplay" easing-function="linear" :interval="interval" :duration="duration" circular="true">
			<swiper-item v-for="(swipeitem, index) in swipearr" :key="index" >
				<image class="swiper-item-image"  :src="swipeitem" mode="heightFix"></image>
				<view v-if="index==(swipearr.length-1)" class="btn-view">
					<button class="register" @click="navito">{{openpageBtnInfo.text}}</button>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>

const app = getApp().globalData;
var util = require("../../utils/util.js");

export default {
	data() {
		return {
			swipearr:[{"thumb":""},{"thumb":""},],
			indicatorDots: true,
			autoplay: false,
			interval: 5000,
			duration: 500,
			openpageBtnInfo:{}
		};
	},

	components: {},
	props: {},
	onLoad: function(options) {
		var that = this
		var productCode = uni.getStorageSync('productCode')
		var projectCode = uni.getStorageSync('projectCode')
		var terminaltype = uni.getStorageSync('terminaltype')
		var dbId = uni.getStorageSync('dbId')
		var menuId = options.menuId
		var modId = options.modId
		var pageName = options.pageName
		var templetName = options.templetName
		console.log(options)
		var machineName = ''
		var mac = ''
		var ip = ''
		uni.getSystemInfo({
			success:function(e){
				machineName = e.deviceBrand + ' ' + e.deviceModel + ' ' + e.deviceType
				mac = e.deviceId
			}
		})
		var injson = '{"productCode":"' + productCode + '","terminalType":"' + terminaltype + '","machineName":"' + machineName + '","mac":"' + mac + '","ip":"' + ip +'","projectCode":"' + projectCode +'","dbId":"' + dbId +'","templetName":"' + templetName + '","pageName":"' + pageName + '","menuId":"' + menuId +'","modId":"' + modId +'","sessionId":""}';
		console.log(injson)
		uni.request({
			url: getApp().globalData.app_address + '?method=saas_PageInfo&parse=json',
			data: injson,
			method: 'POST',
			header: { 'content-type': 'application/x-www-form-urlencoded' },
			success: function(res) {
				var result = res.data;
				console.log(result)
				if(result.rtn==1){
					var picURLs = result.data.page.picURL
					var picURLTemp = []
					if(JSON.stringify(picURLs) != '[]'){
						for(var i=0; i<picURLs.length; i++){
							picURLTemp.push(getApp().globalData.pic_address + picURLs[i])
						}
					}
					
					that.swipearr = picURLTemp
					console.log(that.swipearr)
					var btns = result.data.btns
					if(JSON.stringify(btns) != '[]'){
						for(var i=0; i<btns.length; i++){
							if(btns[i].name == 'openpage'){
								that.openpageBtnInfo = btns[i]
							}
						}
					}
				}
			},
			fail: function(res) {}
		});
	},
	
	methods:{
		navito(){
			var that = this
			var clicked = that.openpageBtnInfo.clicked
			console.log(clicked)
			var pageName = clicked.pageName
			var templetName = clicked.templetName
			var menuId = clicked.menuId
			var modId = clicked.modId
			var title = clicked.title
			uni.setStorageSync('loginpageName',pageName)
			uni.setStorageSync('logintempletName',templetName)
			uni.setStorageSync('loginmenuId',menuId)
			uni.setStorageSync('loginmodId',modId)
			uni.setStorageSync('logintitle',title)
			if(pageName == 'appsj_logon'){
				uni.navigateTo({
					url:'../register/register?title='+title+'&menuId='+menuId+'&modId='+modId+'&pageName='+pageName+'&templetName='+templetName
				})
			}
		},
	}
}
</script>

<style>
	.main-view{width: 100vw;height:100vh;}
	.content-swiper{width: 100vw;height: 100vh;}
	.swiper-item-image{width: 100vw;height: 100vh;}
	.btn-view{left: 50px;right: 50px; margin: 0 auto; bottom: 100px; position: absolute;}
	.register{background: #ff9d29;color: #fff;}
</style>